package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"log"
)

func main() {
	db, err := sql.Open(
		"mysql",
		"root:root@tcp(172.20.0.10:3306)/gogogo?charset=utf8",
	)
	if err != nil {
		log.Fatal("open db error.", err)
		return
	}
	defer db.Close()

	rows, err := db.Query("select * from tbl_student order by id asc limit 2")
	if err != nil {
		log.Fatal("query error.", err)
	}
	defer rows.Close()

	var id int
	var stuNo string
	var name string

	for rows.Next() {
		rows.Scan(&id, &stuNo, &name)
		fmt.Printf("id=%d, stuNo=%s, name=%s\n", id, stuNo, name)
	}

}
